class Solution {
public:
    bool isCompleteTree(TreeNode* root)
    {
        if (root == nullptr)
            return true;
        queue<TreeNode*> q;
        q.push(root);
        bool flag = false;
        while (!q.empty())
        {
            int sz = q.size();
            for (int i = 0; i < sz; i++)
            {
                TreeNode* cur = q.front();
                q.pop();
                if (cur == nullptr)
                    flag = true;
                else
                {
                    if (flag)
                        return false;
                    else
                    {
                        q.push(cur->left);
                        q.push(cur->right);
                    }
                }

            }
        }
        return true;
    }
};